$(function () {
	//获取当前hash改变情况
	window.onhashchange = locationH;

	locationH();

	function locationH() {
		//console.log(location.hash);

		//获取地址
		let hash = location.hash;

		//判定 当前hash显示在哪个页面
		switch (hash) {
			//一级路由
			case '#home':
				$('#main').load('./page/home.html');
				break;

			case '#invest':
				$('#main').load('./page/invest.html');
				break;

			case '#borrow':
				$('#main').load('./page/borrow.html');
				break;

			case '#personage':
				locationt('personage/info')
				break;

			case '#new':
				$('#main').load('./page/new.html');
				break;

			case '#us':
				$('#main').load('./page/us.html');
				break;


			//二级路由
			case '#personage/project':
				locationt('personage/project')
				break;
			case '#personage/info':
				locationt('personage/info')
				break;
			case '#personage/auth':
				locationt('personage/auth')
				break;
			case '#personage/water':
				locationt('personage/water')
				break;
			case '#personage/topUp':
				locationt('personage/topUp')
				break;
			case '#personage/alter':
				locationt('personage/alter')
				break;
			case '#personage/borrowapply':
				locationt('personage/borrowapply')
				break;
			case '#personage/card':
				locationt('personage/card')
				break;
			case '#personage/borrowInfo':
				locationt('personage/borrowInfo')
				break;

			default:
				$('#main').load('./page/home.html');
				break;


		}
		function locationt(hash) {
			$('#main').load('./page/personage.html', function () {
				$('#right-box').load(`./page/${hash}.html`);
			});
		}


		//激活青铜版
		/* if (hash == "") {
			$(`.page-bottom .navbar-nav li:eq(0) a`).closest('li').addClass('active').siblings('li').removeClass('active')
		} else {
			// $(`.page-bottom .navbar-nav li a[href="${hash}"]`).closest('li').addClass('active').siblings('li').removeClass('active')
			
			if(!hash.includes('/')){
				$(`.page-bottom .navbar-nav li a[href="${hash}"]`).closest('li').addClass('active').siblings('li').removeClass('active')
			}else{
				 $(`.page-bottom .navbar-nav li a[href="${hash.split('/')[0]}"]`).closest('li').addClass('active').siblings('li').removeClass('active')
			}
		} */

		//黄金版
		/* let $active;
		if(hash == ""){
			$active=$(`.page-bottom .navbar-nav li:eq(0) a`)
		}else{
			if(!hash.includes('/')){
				$active=$(`.page-bottom .navbar-nav li a[href="${hash}"]`)
			}else{
				$active=$(`.page-bottom .navbar-nav li a[href="${hash.split('/')[0]}"]`)
			}
		}
		$active.closest('li').addClass('active').siblings('li').removeClass('active') */

		//钻石版
		let $active = !hash ? $(`.page-bottom .navbar-nav li:eq(0) a`) : !hash.includes('/')
			? $(`.page-bottom .navbar-nav li a[href="${hash}"]`) : $(`.page-bottom .navbar-nav li a[href="${hash.split('/')[0]}"]`);

		$active.closest('li').addClass('active').siblings('li').removeClass('active')


	}



	//判定
	let locationName = localStorage.getItem('username');
	if (locationName == null) {
		$('.login').html(' <a class="nav-link" href="./login.html">登录</a>')
		$('.register').html('<a class="nav-link" href="./register.html">注册</a>')
	} else {
		$('.login').html(` <a class="nav-link" href="#">${locationName}</a>`)
		$('.register').html(`<a class="nav-link" href="#" id="del">注销</a>`)


	}
	//点击注销按钮，注销登录状态
	$('#del').click(function () {
		//alert('1')
		localStorage.removeItem('username');
		location.href = '/'
	})

	//过20秒，自动退出登录
	let timeId = setInterval(function () {
		let endtime = localStorage.getItem('time');
		let dangtime = new Date().getTime();
		if (dangtime > endtime) {
			//删除本地的数据
			localStorage.removeItem('username');
			localStorage.removeItem('time');

			//关闭计时器
			clearInterval(timeId);

			$('.login').html(' <a class="nav-link" href="./login.html">登录</a>')
			$('.register').html('<a class="nav-link" href="./register.html">注册</a>')
		}
	}, 1000)



	//二维码
	$('.ke').hover(function () {
		$('#img').css('display', 'block')
	}, function () {
		$('#img').css('display', 'none')
	})



})